package com.mjh.controller;

import com.alibaba.excel.EasyExcel;

import com.mjh.service.CustomerService;

import com.mjh.vo.CustomerVoo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.util.List;

@RequestMapping("/api/download")
@Controller
public class DownloadController {

    @Autowired
    private CustomerService customerService;


    @GetMapping("/excel/customer")
    public void exportAllCustomerExcel(HttpServletResponse response) throws IOException {

        // 查询导出的数据
        List<CustomerVoo> list = customerService.queryAllCustomerList();

        // 设置响应头信息
        response.setHeader("Content-Disposition","attachment; filename=customer.xls");
        // 导出
        EasyExcel.write(response.getOutputStream(), CustomerVoo.class).sheet("模板222").doWrite(list);
    }
}